﻿using DevExpress.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using TestingApp.Models;
using TestingApp.Services;

namespace TestingApp.ViewModels.Admin {
    public class TestEditorPageViewModel  : BindableBase {
        private readonly Repository _repository;

        public Test Test { get; set; }

        public TestEditorPageViewModel(Repository repository)  {
            Test = new Test {

                Title = "Test по химии 2",

                Questions = new ObservableCollection<Question> {

                    new Question {
                        Text = "1. Кто открыл атом",

                        Answers = new ObservableCollection<Answer>{

                            new Answer {
                                Text = "Эрнест Резерфорд",
                                IsCorrect = true
                            },

                             new Answer {
                                Text = "Дмитрий Менеделеев",
                                IsCorrect = false
                            }
                        }
                    },

                    new Question {
                        Text = "2. Кто создал таблицу элементов",

                        Answers = new ObservableCollection<Answer>{

                            new Answer {
                                Text = "Эрнест Резерфорд",
                                IsCorrect = false
                            },

                             new Answer {
                                Text = "Дмитрий Менеделеев",
                                IsCorrect =true
                            }
                        }
                    },
                }
            };
           _repository = repository;
        }


        public ICommand Save => new DelegateCommand(() =>   {
            if (string.IsNullOrWhiteSpace(Test.Title)) {
                MessageBox.Show("Введите название КР!!!");
                return;
            }
            _repository.Save(Test);
            MessageBox.Show("Тест сохранен в БД");
        });




    }
}
